package com.wn.web;

import com.wn.auth.CookieUtil;
import com.wn.auth.JWTUtil;
import com.wn.auth.RsaUtils;
import com.wn.common.Const;
import com.wn.pojo.User;
import com.wn.response.ResponseCode;
import com.wn.response.ServerResponse;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;


@CrossOrigin
@RestController
public class UserController {
    @PostMapping("login")
    public ServerResponse login(@RequestBody User user, HttpServletResponse response){
        String resName="tom";
        String resPassword="123";
        if(user.getName().equals(resName)&&user.getPassword().equals(resPassword)){

            String token = JWTUtil.generateToken(user, Const.PRIVATE_KEY, 30);
           //把token存到cookie中
           // CookieUtil.responseCookie(token,response);
            return  new ServerResponse(ResponseCode.SUCCESS,token,"登录成功");
        }else {
         return  new ServerResponse(ResponseCode.ERROR,null,"登录失败");
        }

        }


}
